home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWFiles / SLFilPar.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  20.1 KB  |  737 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLFilPar.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef SLFILPAR_H
  13. #include "SLFilPar.h"
  14. #endif
  15.  
  16. #ifndef FWSOMENV_H
  17. #include "FWSOMEnv.h"
  18. #endif
  19.  
  20. #ifndef FWFILESP_H
  21. #include "FWFileSp.h"
  22. #endif
  23.  
  24. #ifndef FWFILESY_H
  25. #include "FWFileSy.h"
  26. #endif
  27.  
  28. #ifndef FWBNDSTR_H
  29. #include "FWBndStr.h"
  30. #endif
  31.  
  32. #ifndef FWEXCLIB_H
  33. #include "FWExcLib.h"
  34. #endif
  35.  
  36. #if defined(FW_BUILD_WIN) && !defined(FWMEMMGR_H)
  37. #include "FWMemMgr.h"
  38. #endif
  39.  
  40. #if defined(FW_BUILD_WIN) && !defined(__DOS_H)
  41. #include <dos.h>
  42. #endif
  43.  
  44. #if defined(FW_BUILD_WIN) && !defined(__DIRECT_H)
  45. #include <direct.h>
  46. #endif
  47.  
  48. #if defined(FW_BUILD_WIN) && !defined(__IO_H)
  49. #include <io.h>
  50. #endif
  51.  
  52. #ifdef FW_BUILD_WIN16
  53. extern "C" void FAR PASCAL DOS3Call();                // We don't do "int 21h" under Windows
  54. #endif
  55.  
  56.  
  57. #ifdef FW_BUILD_WIN16
  58. static short privPrimitiveGetDefaultDrive();
  59. static short privPrimitiveGetCurrentDir(FW_Char* namePtr);
  60. #endif
  61.  
  62. #ifdef FW_BUILD_MAC
  63. #pragma segment File
  64. #endif
  65.  
  66. //========================================================================================
  67. // CLASS FW_PrivFileSystemParser
  68. //========================================================================================
  69.  
  70. //----------------------------------------------------------------------------------------
  71. //    FW_PrivFileSystemParser_IsPartialPath
  72. //
  73. //    Return TRUE if pathName specifies a partial pathName.
  74. //
  75. //  On Windows, only a fully qualified pathname will return FALSE.  That is a path that
  76. //    specifies a drive and directory starting from the root directory of the drive.
  77. //  On Mac, a partial pathname is any string that starts with a path separator character.
  78. //----------------------------------------------------------------------------------------
  79.  
  80. FW_Boolean FW_PrivFileSystemParser_IsPartialPath(FW_HString pathNameRep) 
  81. {
  82.     FW_Boolean result = TRUE;
  83.  
  84.     FW_CString pathName(pathNameRep);
  85.     
  86. #ifdef FW_BUILD_WIN
  87.     if (pathName.GetByteLength() > 0)
  88.     {
  89.         FW_CString32 drivePathSeparator(&FW_kDriveDelimiter, 1);
  90.         FW_CharacterPosition drivePosition;
  91.         
  92.         drivePathSeparator += FW_kPathDelimiter;
  93.         
  94.         if (pathName.FindSubString(drivePathSeparator, drivePosition))
  95.             result = FALSE;
  96.     }
  97. #endif
  98.  
  99. #ifdef FW_BUILD_MAC
  100.     if (pathName.GetByteLength() > 0)
  101.         result = (pathName[0] == FW_kPathDelimiter);
  102. #endif
  103.  
  104.     return (result);
  105. }
  106.  
  107.  
  108. //----------------------------------------------------------------------------------------
  109. //    FW_PrivFileSystemParser_AddDelimiter
  110. //
  111. //  Adds a trailing backslash if appropriate.  It will not add a delimiter if one already
  112. //    exists, the path length is zero (indicating the default directory),or if the last 
  113. //    character is a colon (indicating a drive name).
  114. //----------------------------------------------------------------------------------------
  115.  
  116. void FW_PrivFileSystemParser_AddDelimiter(FW_HString* pathNameRep) 
  117. {
  118.     FW_CharacterPosition lastCharacter;
  119.  
  120.     FW_CString pathName(*pathNameRep);
  121.     lastCharacter = pathName.GetCharacterLength() - 1;
  122.  
  123.     if (lastCharacter >= 0)
  124.     {
  125. #ifdef FW_BUILD_WIN
  126.         if ((pathName[lastCharacter] != FW_kPathDelimiter) && (pathName[lastCharacter] != FW_kDriveDelimiter))
  127.             pathName += FW_kPathDelimiter;
  128. #endif
  129.  
  130. #ifdef FW_BUILD_MAC
  131.         if (pathName[lastCharacter] != FW_kPathDelimiter)
  132.             pathName += FW_kPathDelimiter;
  133. #endif
  134.  
  135.     }
  136. }
  137.  
  138.  
  139. #ifdef FW_BUILD_WIN16
  140. //----------------------------------------------------------------------------------------
  141. // privPrimitiveGetDefaultDrive
  142. //
  143. //  Return the current default drive number where A=0, B=1, C=2, etc.
  144. //----------------------------------------------------------------------------------------
  145. short privPrimitiveGetDefaultDrive()
  146. {
  147.     short driveNumber = -1;
  148.     
  149.     __asm {
  150.         mov        ah, 19h
  151.     }
  152.     
  153.     DOS3Call();
  154.     
  155.     __asm {
  156.         mov        driveNumber, ax
  157.     }
  158.     
  159.     return (driveNumber);
  160. }
  161. #endif
  162.  
  163.  
  164. #ifdef FW_BUILD_WIN16
  165. //----------------------------------------------------------------------------------------
  166. // privPrimitiveGetCurrentDir
  167. //
  168. //  namePtr is a pointer to a buffer.  On return, this buffer will contain the directory
  169. //    name.  This buffer should be at least 64 bytes long.
  170. //  Returns an error code.
  171. //----------------------------------------------------------------------------------------
  172. short privPrimitiveGetCurrentDir(FW_Char* namePtr)
  173. {
  174.     FW_PlatformError theError = FW_xNoError;
  175.     
  176.     __asm {
  177.         push    ds
  178.         lds        si, [namePtr]
  179.         mov        dl, 00h
  180.         mov     ah, 47h
  181.     }
  182.     
  183.     DOS3Call();
  184.         
  185.     __asm {
  186.         pop     ds
  187.         jc        _error
  188.         xor     ax, ax
  189.     }
  190.             
  191.     _error:
  192.     
  193.     __asm {
  194.         mov        theError, ax
  195.     }
  196.     
  197.     return (theError);
  198. }
  199. #endif
  200.  
  201.  
  202. //----------------------------------------------------------------------------------------
  203. // FW_PrivFileSystemParser_PrivGetWorkingDirectory
  204. //----------------------------------------------------------------------------------------
  205.  
  206. FW_PlatformError FW_PrivFileSystemParser_PrivGetWorkingDirectory(FW_HString* directoryNameRep)
  207. {
  208.     FW_PlatformError theError = FW_xNoError;
  209.     
  210.     FW_CString directoryName(*directoryNameRep);
  211.     directoryName = "";
  212.  
  213. #ifdef FW_BUILD_WIN16
  214.     FW_CString255 buffer;
  215.     const FW_Char* namePtr = (const FW_Char*)buffer;
  216.     short driveNumber = privPrimitiveGetDefaultDrive();
  217.     
  218.     directoryName = "";
  219.     directoryName += (FW_Char)(driveNumber + 'a');
  220.     directoryName += FW_kDriveDelimiter;
  221.     directoryName += FW_kPathDelimiter;
  222.     
  223.     theError = privPrimitiveGetCurrentDir((FW_Char*)namePtr);
  224.     if (theError == FW_xNoError)
  225.         directoryName += namePtr;
  226. #endif
  227.  
  228. #ifdef FW_BUILD_WIN32
  229.     char* dirBuffer = new char[MAX_PATH];
  230.     long dirNameLength = ::GetCurrentDirectory(MAX_PATH, dirBuffer);
  231.     
  232.     if(dirNameLength == 0)
  233.         theError = ::GetLastError();
  234.     else
  235.         directoryName = dirBuffer;
  236.  
  237.     delete [] dirBuffer;
  238. #endif
  239.  
  240.  
  241. #ifdef FW_BUILD_MAC
  242.     short vRefNum;
  243.     long dirID;
  244.         
  245.     theError = ::HGetVol(NULL, &vRefNum, &dirID);
  246.     
  247.     if (theError == FW_xNoError)
  248.         theError = FW_PrivFileSystemParser_MacGenerateFullPathName(vRefNum, dirID, directoryName);
  249.     
  250. #endif
  251.     return theError;
  252. }
  253.  
  254.  
  255. //----------------------------------------------------------------------------------------
  256. //    FW_PrivFileSystemParser_HasExtension
  257. //
  258. //  Return TRUE if the file name has a dot-extension.  Return the dot position in the
  259. //    dotPosition parameter.
  260. //    This routine searches the string backwards for the first path delimiter it sees.  
  261. //    It then searches forwards searching for the first period it sees.
  262. //    It returns TRUE if it finds the period.
  263. //----------------------------------------------------------------------------------------
  264.  
  265. FW_Boolean FW_PrivFileSystemParser_HasExtension(FW_HString fileNameRep,
  266.                                                 FW_CharacterPosition& dotPosition) 
  267. {
  268.     FW_CString fileName(fileNameRep);
  269.     FW_Boolean result = FALSE;
  270.     FW_CharacterPosition pathDelimiterPosition;
  271.  
  272.     dotPosition = 0;
  273.  
  274.     if (fileName.GetByteLength() > 0)
  275.     {
  276.         result = fileName.FindCharacter(FW_kPathDelimiter, pathDelimiterPosition, fileName.GetByteLength(), FW_kBackwards);
  277.         if (!result)
  278.             pathDelimiterPosition = -1;
  279.  
  280.         result = fileName.FindCharacter(FW_kExtensionDelimiter, dotPosition, pathDelimiterPosition + 1, FW_kForwards);
  281.     }
  282.  
  283.     return (result);
  284. }
  285.  
  286.  
  287. //----------------------------------------------------------------------------------------
  288. //    FW_PrivFileSystemParser_ChangeExtension
  289. //
  290. //  Return a pathname with the specified extension attached.  fileName can be a full or
  291. //    partial pathname.  If an extension already exists, it will be overwritten.
  292. //----------------------------------------------------------------------------------------
  293.  
  294. void FW_PrivFileSystemParser_ChangeExtension(FW_HString pathNameRep,
  295.                                              FW_HString extensionRep,
  296.                                              FW_HString* returnNameRep) 
  297. {
  298.     FW_CString pathName(pathNameRep);
  299.     FW_CString extension(extensionRep);
  300.     FW_CString returnName(*returnNameRep);
  301.     
  302.     FW_CharacterPosition dotPosition;
  303.  
  304.     returnName = pathName;
  305.  
  306.     // If there is already an extension, trancate it and the dot.
  307.     if (FW_PrivFileSystemParser_HasExtension(pathName, dotPosition))
  308.         returnName.Truncate(dotPosition);
  309.  
  310.     returnName += FW_kExtensionDelimiter;
  311.     returnName += extension;
  312. }
  313.  
  314.  
  315. //----------------------------------------------------------------------------------------
  316. //    FW_PrivFileSystemParser_GetExtension
  317. //
  318. //  Return the extension to this file in extension.  If no extension exists, then FALSE
  319. //    is returned, otherwise TRUE is returned.
  320. //----------------------------------------------------------------------------------------
  321.  
  322. FW_Boolean FW_PrivFileSystemParser_GetExtension(FW_HString pathNameRep,
  323.                                                 FW_HString* extensionRep) 
  324. {
  325.     FW_CString pathName(pathNameRep);
  326.     FW_CString extension(*extensionRep);
  327.     
  328.     FW_CharacterPosition dotPosition;
  329.     FW_Boolean result = FALSE;
  330.  
  331.     extension = "";
  332.  
  333.     // Delete everything before the extension, including the dot.
  334.     if (FW_PrivFileSystemParser_HasExtension(pathName, dotPosition))
  335.     {
  336.         FW_LChar charToAdd;
  337.  
  338.         FW_CStringReader reader(pathName);
  339.         reader.SetPosition(dotPosition + 1);
  340.  
  341.         while ((charToAdd = reader.GetCharacterAndAdvance()) != FW_kNulCharacter)
  342.             extension += charToAdd;
  343.  
  344.         result = TRUE;
  345.     }
  346.  
  347.     return (result);
  348. }
  349.  
  350.  
  351. //----------------------------------------------------------------------------------------
  352. //    FW_PrivFileSystemParser_GetFileName
  353. //
  354. //  Return the filename portion without any path information.  The filename includes
  355. //    the file extension.  
  356. //----------------------------------------------------------------------------------------
  357.  
  358. FW_Boolean FW_PrivFileSystemParser_GetFileName(FW_HString pathNameRep,
  359.                                                FW_HString* fileNameRep) 
  360. {
  361.     FW_CString pathName(pathNameRep);
  362.     FW_CString fileName(*fileNameRep);
  363.  
  364.     FW_CharacterPosition delimiterPosition;
  365.     FW_Boolean result = FALSE;
  366.  
  367.     fileName = "";
  368.     
  369.     if (pathName.GetByteLength() > 0)
  370.     {
  371.         result = pathName.FindCharacter(FW_kPathDelimiter, delimiterPosition, pathName.GetByteLength(), FW_kBackwards);
  372.  
  373. #ifdef FW_BUILD_WIN
  374.         // Only needed for Windows since path and drive delimiters are different.
  375.         if (!result)
  376.             result = pathName.FindCharacter(FW_kDriveDelimiter, delimiterPosition, pathName.GetByteLength(), FW_kBackwards);
  377. #endif
  378.  
  379.         if (result)
  380.         {
  381.             FW_CStringReader reader(pathName);
  382.             reader.SetPosition(delimiterPosition + 1);
  383.  
  384.             FW_LChar charToAdd;
  385.             while ((charToAdd = reader.GetCharacterAndAdvance()) != FW_kNulCharacter)
  386.                 fileName += charToAdd;
  387.         }
  388.     }
  389.     else
  390.         fileName = "";
  391.  
  392.     return (result);
  393. }
  394.  
  395.  
  396. //----------------------------------------------------------------------------------------
  397. //    FW_PrivFileSystemParser_GetJustFileName
  398. //
  399. //  Get the full file name and truncate off the dot and extension.
  400. //----------------------------------------------------------------------------------------
  401.  
  402. FW_Boolean FW_PrivFileSystemParser_GetJustFileName(FW_HString pathNameRep,
  403.                                                    FW_HString* fileNameRep) 
  404. {
  405.     FW_CString pathName(pathNameRep);
  406.     FW_CString fileName(*fileNameRep);
  407.     
  408.     FW_CharacterPosition dotPosition;
  409.  
  410.     FW_Boolean result = FW_PrivFileSystemParser_GetFileName(pathName, fileName);
  411.  
  412.     if (FW_PrivFileSystemParser_HasExtension(fileName, dotPosition))
  413.         fileName.Truncate(dotPosition);
  414.  
  415.     return (result);
  416. }
  417.  
  418.  
  419.  
  420.  
  421. //===========================================
  422. // Windows Routines
  423. //===========================================
  424.  
  425. #ifdef FW_BUILD_WIN
  426. //----------------------------------------------------------------------------------------
  427. //    FW_PrivFileSystemParser_WinGetPathName
  428. //
  429. //  Returns the directory information in pathName.  If the directory is anything but a root
  430. //    directory, then there is no trailing backslash on the end of the path.  This makes
  431. //    it easier to create FW_PDirectorySpecification's.
  432. //  Returns FALSE if there is no path information, otherwise returns TRUE to indicate some
  433. //    path information was present.  The information that gets returned may still be part
  434. //    of a partial pathname.
  435. //----------------------------------------------------------------------------------------
  436.  
  437. FW_Boolean FW_PrivFileSystemParser_WinGetPathName(FW_HString fullPathNameRep,
  438.                                                   FW_HString* pathNameRep) 
  439. {
  440. #if 1
  441.     FW_CString fullPathName(fullPathNameRep);
  442.     FW_CString pathName(*pathNameRep);
  443.  
  444.     char szFullPathName[_MAX_PATH];
  445.     fullPathName.ExportCString(szFullPathName);
  446.     
  447.     char* lpszSlash = strrchr(szFullPathName, '\\');
  448.     char* lpszColon = strrchr(szFullPathName, ':');
  449.     
  450.     if (lpszSlash != NULL)
  451.     {
  452.         if (lpszSlash > szFullPathName && *(lpszSlash - 1) == ':')
  453.             ++ lpszSlash;
  454.  
  455.         *lpszSlash = 0;
  456.         pathName = szFullPathName;
  457.         
  458.         return TRUE;
  459.     }
  460.     
  461.     if (lpszColon != NULL)
  462.     {
  463.         lpszColon[1] = 0;
  464.         pathName = szFullPathName;
  465.         
  466.         return TRUE;
  467.     }
  468.     
  469.     return FALSE;
  470. #else
  471.     //KVV  This code calls FW_CString::GetLength() which does ASSERT(false) !
  472.     //JEL, 12/12/95: I rewrote the code to use GetByteLength instead of GetLength, but this code
  473.     // will definitely still fail since I removed StringTools.  We need to
  474.     // rewrite it to use the string searching member functions, but even
  475.     // these aren't fully implemented yet.
  476.     FW_CharacterPosition backSlashPosition = 0;
  477.     FW_CharacterPosition colonPosition = 0;
  478.     FW_CharacterPosition delimiterPosition;
  479.  
  480.     FW_Boolean backSlashResult = FALSE;
  481.     FW_Boolean colonResult = FALSE;
  482.     FW_Boolean functionResult = FALSE;
  483.  
  484.     pathName = "";
  485.  
  486.     if (fullPathName.GetByteLength() > 0)
  487.     {
  488.         // Search backwards for the first character in the delimiter set of '\' and ':'.
  489.         FW_CStringTool *tool = FW_CStringTool::GetCurrentStringTool();
  490.  
  491.         backSlashResult = tool->FindCharacter(fullPathName, FW_kPathDelimiter, backSlashPosition, fullPathName.GetByteLength(), FW_kBackwards);
  492.         colonResult = tool->FindCharacter(fullPathName, FW_kDriveDelimiter, colonPosition, fullPathName.GetByteLength(), FW_kBackwards);
  493.  
  494.         delimiterPosition = FW_Maximum(backSlashPosition, colonPosition);
  495.  
  496.         // If no delimiters were found, then there is no path information here. 
  497.         // Else return what path information there was.
  498.  
  499.         if (backSlashResult || colonResult)
  500.         {
  501.             if (delimiterPosition == 0)
  502.                 pathName += (char) (fullPathName[delimiterPosition]);
  503.             else
  504.             {
  505.                 pathName = fullPathName;
  506.  
  507.                 if (fullPathName[delimiterPosition] == FW_kPathDelimiter)
  508.                 {
  509.                     // If the directory is the root directory, leave the trailing backslash.
  510.                     //   Otherwise remove it.
  511.                     if (fullPathName[(FW_CharacterPosition)(delimiterPosition - 1)] == FW_kDriveDelimiter)
  512.                         pathName.Truncate(delimiterPosition + 1);
  513.                     else
  514.                         pathName.Truncate(delimiterPosition);
  515.                 }
  516.                 else
  517.                     pathName.Truncate(delimiterPosition + 1);
  518.             }
  519.  
  520.             functionResult = TRUE;
  521.         }
  522.     }
  523.  
  524.     return (functionResult);
  525. #endif
  526. }
  527. #endif
  528.  
  529.  
  530. #ifdef FW_BUILD_WIN
  531. //----------------------------------------------------------------------------------------
  532. //    FW_PrivFileSystemParser_WinGetDrivePath
  533. //
  534. //  Returns the drive letter and colon character in drivePath if a drive was specified.
  535. //    If no drive was specified, then FALSE is returned.  The program can use this to
  536. //    determine whether or not pathName specifies a partial path.
  537. //----------------------------------------------------------------------------------------
  538.  
  539. FW_Boolean FW_PrivFileSystemParser_WinGetDrivePath(FW_HString pathNameRep,
  540.                                                    FW_HString* drivePathRep) 
  541. {
  542.     FW_CString pathName(pathNameRep);
  543.     FW_CString drivePath(*drivePathRep);
  544.  
  545.     FW_CharacterPosition delimiterPosition;
  546.     FW_Boolean result = FALSE;
  547.  
  548.     drivePath = "";
  549.  
  550.     if (pathName.GetByteLength() > 0)
  551.     {
  552.         if (pathName.FindCharacter(FW_kDriveDelimiter, delimiterPosition, pathName.GetByteLength(), FW_kBackwards))
  553.         {
  554.             drivePath = pathName;
  555.             drivePath.Truncate(delimiterPosition + 1);
  556.             result = TRUE;
  557.         }
  558.     }
  559.  
  560.     return (result);
  561. }
  562. #endif
  563.  
  564.  
  565. #ifdef FW_BUILD_WIN
  566. //----------------------------------------------------------------------------------------
  567. //    FW_PrivFileSystemParser_WinExpandPartialPath
  568. //
  569. //  Expands a partial pathName into a full pathName based on the current drive and
  570. //    directory.  
  571. //  On entry, pathName contains the partial pathname.  
  572. //  On exit, pathName contains the fully qualified pathname.
  573. //----------------------------------------------------------------------------------------
  574.  
  575. void FW_PrivFileSystemParser_WinExpandPartialPath(FW_HString* pathNameRep) 
  576. {
  577.     FW_CString pathName(*pathNameRep);
  578.  
  579.     FW_PlatformError theError = FW_xNoError;
  580. FW_UNUSED(theError);
  581.  
  582. #ifdef FW_BUILD_WIN16
  583.     // [KVV] Instead of this tedious code, can use OpenFile(OF_PARSE…)
  584.  
  585.     if (IsPartialPath(pathName))
  586.     {
  587.         FW_CString drivePath;
  588.         FW_CString tempPathName;
  589.  
  590.         if (WinGetDrivePath(pathName, drivePath))
  591.         {
  592.             // PathNames of form c:dir\file.ext are being phased out.  Do not use.
  593.             FW_ASSERT(FALSE);
  594.         }
  595.         else
  596.         {
  597.             // Both these cases are built on top of the current directory or drive.
  598.             PrivGetWorkingDirectory(tempPathName);
  599.             
  600.             if ((pathName.GetByteLength() > 0) && (pathName[0] == FW_kPathDelimiter))
  601.             {
  602.                 // In this case, the path is in the form '\dir1\file.txt'
  603.                 //   So all we need to do is add the drive.
  604.                 WinGetDrivePath(tempPathName, drivePath);
  605.                 
  606.                 pathName.Prepend(drivePath);
  607.             }
  608.             else
  609.             {
  610.                 // In this case, the path is in the form 'dir1\file.txt'
  611.                 //   So we need to add the current working directory.
  612.                 if (pathName.GetByteLength() > 0)
  613.                 {
  614.                     AddDelimiter(tempPathName);
  615.                     tempPathName += pathName;
  616.                 }
  617.  
  618.                 pathName = tempPathName;
  619.             }
  620.         }
  621.     }
  622. #endif
  623.  
  624. #ifdef FW_BUILD_WIN32
  625.     // ??? This may or may not be a valid thing to do on Win32.  It needs to be verified.
  626.  
  627.     char szPathName[_MAX_PATH];
  628.     char szFullName[_MAX_PATH];
  629.     
  630.     char* filePortion;
  631.     
  632.     pathName.ExportCString(szPathName);
  633.  
  634.     long bufferSize = ::GetFullPathName(szPathName, MAX_PATH, szFullName, &filePortion);
  635.  
  636.     // Errors are getting eaten for now.  But I still want to see them when
  637.     //   debugging - jjw 8/12/93
  638.     if (bufferSize == 0)
  639.         theError = ::GetLastError();
  640.     else
  641.         pathName = szFullName;
  642. #endif
  643. }
  644. #endif
  645.  
  646.  
  647. //===========================================
  648. // Macintosh Routines
  649. //===========================================
  650.  
  651. #ifdef FW_BUILD_MAC
  652. //----------------------------------------------------------------------------------------
  653. //    FW_PrivFileSystemParser_MacGenerateFullPathName
  654. //
  655. //    Generate a pathname based on the vRefNum and dirID passed to the function.  Return
  656. //    TRUE if pathName contains a valid path including volume name.  If this routine 
  657. //    returns FALSE, the contents of pathName are undefined.  
  658. //----------------------------------------------------------------------------------------
  659.  
  660. OSErr FW_PrivFileSystemParser_MacGenerateFullPathName(short vRefNum,
  661.                                                       long dirID,
  662.                                                       FW_HString* pathNameRep) 
  663. {
  664.     FW_CString pathName(*pathNameRep);
  665.  
  666.     CInfoPBRec paramBlock;
  667.     Str255 dirName = "\p";
  668.     OSErr theError = noErr;
  669.     FW_CString tempString;
  670.  
  671.     // Casts required for compilation.
  672.     paramBlock.dirInfo.ioNamePtr = (StringPtr) &dirName;
  673.     paramBlock.dirInfo.ioVRefNum = vRefNum;
  674.     paramBlock.dirInfo.ioDrParID = dirID;
  675.     paramBlock.dirInfo.ioFDirIndex = -1;
  676.  
  677.     do
  678.     {
  679.         paramBlock.dirInfo.ioDrDirID = paramBlock.dirInfo.ioDrParID;
  680.  
  681.         theError = ::PBGetCatInfoSync(¶mBlock);
  682.         if (theError != noErr)
  683.             return (theError);
  684.  
  685.         // Casts required for compilation.
  686.         tempString.ReplaceAll((FW_PascalChar*)&dirName);
  687.         tempString += ":";
  688.         tempString += pathName;
  689.         pathName = tempString;
  690.     } while (paramBlock.dirInfo.ioDrDirID != fsRtDirID);
  691.  
  692.     return (noErr);
  693. }
  694. #endif
  695.  
  696.  
  697. #ifdef FW_BUILD_MAC
  698. //----------------------------------------------------------------------------------------
  699. //    FW_PrivFileSystemParser_MacGenerateDirectory
  700. //
  701. //    Get the name of the directory specified
  702. //----------------------------------------------------------------------------------------
  703.  
  704. OSErr FW_PrivFileSystemParser_MacGenerateDirectory(short vRefNum,
  705.                                                    long dirID,
  706.                                                    FW_ODirectorySpecification* directory) 
  707. {
  708.     CInfoPBRec paramBlock;
  709.     Str255 dirName = "\p";
  710.     OSErr theError = noErr;
  711.     FSSpec theMacSpec;
  712.  
  713.     // Casts required for compilation.
  714.     paramBlock.dirInfo.ioNamePtr = (StringPtr) & dirName;
  715.     paramBlock.dirInfo.ioVRefNum = vRefNum;
  716.     paramBlock.dirInfo.ioDrParID = dirID;
  717.     paramBlock.dirInfo.ioFDirIndex = -1;
  718.  
  719.     paramBlock.dirInfo.ioDrDirID = paramBlock.dirInfo.ioDrParID;
  720.  
  721.     theError = ::PBGetCatInfoSync(¶mBlock);
  722.     if (theError != noErr)
  723.         return (theError);
  724.  
  725.     theError = ::FSMakeFSSpec(vRefNum, paramBlock.dirInfo.ioDrParID, dirName, &theMacSpec);
  726.  
  727.     if (theError != noErr)
  728.         return (theError);
  729.  
  730.     FW_SOMEnvironment ev;
  731.     directory->AssignFileSpec(ev, &theMacSpec);
  732.     return (noErr);
  733. }
  734. #endif
  735.  
  736.  
  737.